package org.fffd.l23o6.util.paystub;

import io.github.lyc8503.spring.starter.incantation.exception.BizException;
import org.fffd.l23o6.exception.BizError;
import org.fffd.l23o6.pojo.enum_.OrderStatus;

import java.math.BigDecimal;

//修改：支付宝桩程序
public class AlipayStub {
    private static BigDecimal money = BigDecimal.valueOf(30000);

    public enum PayResult {
        SUCCESS("支付成功"),
        LACK_OF_BALANCE("余额不足"),
        ERROR("出错");
        private final String message;

        PayResult(String message) {
            this.message = message;
        }
    }

    public AlipayStub() {}

    public AlipayStub(int money) {
        AlipayStub.money = BigDecimal.valueOf(money);
    }

    public static BigDecimal getMoney() {
        return money;
    }

    public static PayResult pay(BigDecimal paymentAmount) {
        try {
            if (money.compareTo(paymentAmount) >= 0) {
                money = money.subtract(paymentAmount);
                return PayResult.SUCCESS;
            } else {
                return PayResult.LACK_OF_BALANCE;
            }

        } catch (Exception e) {
            return PayResult.ERROR;
        }
    }

    public static PayResult refund(BigDecimal paymentAmount) {
        try {
            money = money.add(paymentAmount);

            return PayResult.SUCCESS;
        } catch (Exception e) {
            return PayResult.ERROR;
        }
    }
}